import java.util.InputMismatchException;
import java.util.Scanner;

//Exception klasse
public class Exception {
	//textException metode
	public String textException(){
		boolean test = false;
		Scanner input = new Scanner(System.in);
		
		while (test == false){
			try
			{
				String text = input.next();
				test = true;
				return text;
			}//end try
			catch(InputMismatchException inputMistmatchException)
			{
				System.err.printf("\nException: %s", inputMistmatchException);
				input.nextLine();
				System.err.printf("Please enter text:");
			}//end catch
		}//end while-loop
		input.close();
		return null;
	}//end textException metode
	
	//Exception metode til tal
	public double numberException(){
		boolean test = false;
		Scanner input = new Scanner(System.in);
		
		while (test == false){
			try
			{
				double number = input.nextDouble();
				test = true;
				return number;
			}//end try
			catch(InputMismatchException inputMistmatchException)
			{
				System.err.printf("\nError: %s\n", inputMistmatchException);
				input.nextLine();
				System.err.printf("Please enter numbers only: ");
			}//end catch
		}//end while-loop
		input.close();
		return 0;
	}//end numberException metode
	
	//Exception metode til heltal
	public int menuException(){
		boolean test = false;
		Scanner input = new Scanner(System.in);
		
		while (test == false){
			try{
				int number = input.nextInt();
				test = true;
				return number;
				
			}catch(InputMismatchException inputMistmatchException){
				System.err.printf("\nError: %s\n", inputMistmatchException);
				input.nextLine();
				System.err.printf("Please enter whole numbers only: ");
			}
		}
		input.close();
		return 0;
	}//end menuException
		
}//end Exception klasse
